﻿Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports Exp.DAL
Imports Exp.Model
Public Class ResortSeason_service
    Public Function GetAll() As List(Of REM_ResortSeason)
        Dim ctx As New EXPEntities
        Dim list = ctx.REM_ResortSeason.ToList()
        Return list
    End Function
    Public Function GetByID(ByVal iResortID As Integer, ByVal iSeasonID As Integer) As List(Of REM_ResortSeason)
        Dim ctx As New EXPEntities
        Dim obj = ctx.REM_ResortSeason.Where(Function(o) o.Resort_ID = iResortID And o.Season_ID = iSeasonID).ToList()
        Return obj
    End Function
    Public Function GetByResortID(ByVal iResortID As Integer) As List(Of REM_ResortSeason)
        Dim ctx As New EXPEntities
        Dim obj = ctx.REM_ResortSeason.Where(Function(o) o.Resort_ID = iResortID).ToList()
        Return obj
    End Function
    Public Sub Add(objREM_ResortSeason As REM_ResortSeason)
        Dim ctx As New EXPEntities
        ctx.REM_ResortSeason.AddObject(objREM_ResortSeason)
        ctx.SaveChanges()
    End Sub
    Public Sub Delete(ByVal iResortID As Integer, ByVal iSeasonID As Integer)
        Dim ctx As New EXPEntities
        Dim obj = ctx.REM_ResortSeason.Where(Function(o) o.Resort_ID = iResortID And o.Season_ID = iSeasonID).FirstOrDefault()
        ctx.REM_ResortSeason.DeleteObject(obj)
        ctx.SaveChanges()
    End Sub
    Public Sub DeleteAll(ByVal iResortID As Integer)
        Dim ctx As New EXPEntities
        Dim LREM_ResortSeason As New List(Of REM_ResortSeason)
        LREM_ResortSeason = ctx.REM_ResortSeason.Where(Function(o) o.Resort_ID = iResortID).ToList()
        If LREM_ResortSeason Is Nothing Then
            Return
        End If
        If LREM_ResortSeason.Count > 0 Then
            For index = 0 To LREM_ResortSeason.Count - 1
                Dim obj = ctx.REM_ResortSeason.Where(Function(o) o.Resort_ID = iResortID).FirstOrDefault()
                If Not obj Is Nothing Then
                    If obj.Resort_ID > 0 Then
                        ctx.REM_ResortSeason.DeleteObject(obj)
                        ctx.SaveChanges()
                    End If
                End If
            Next
        End If
    End Sub
    Public Sub Edit(objREM_ResortSeason As REM_ResortSeason)
        Dim ctx As New EXPEntities
        Dim obj = ctx.REM_ResortSeason.Where(Function(o) o.Resort_ID = objREM_ResortSeason.Season_ID And o.Season_ID = objREM_ResortSeason.Resort_ID).FirstOrDefault()
        obj.Resort_ID = objREM_ResortSeason.Resort_ID
        obj.Season_ID = objREM_ResortSeason.Season_ID
        obj.StartDate = objREM_ResortSeason.StartDate
        obj.EndDate = objREM_ResortSeason.EndDate
        ctx.SaveChanges()
    End Sub
End Class
